<template>
    <div></div>
</template>

<script>
import { getList } from '@/api/table'
export default {
    data() {
        return{
          list: null,
          getList: [],
          dayNumber: 0,
          newArr1:[],
          newArr2: [],
          listLoading: true,
          dialogTableVisible: false,
          // tableData:[]
        }
    },
    created() {
      this.fetchData()
      this.apiarrcge()
    },
    methods: {
      fetchData() {
        this.listLoading = true
        getList().then(response => {
          this.list = response.data.items
          this.listLoading = false
        })
      },
      apiarrcge() {
        var date = new Date();
        var NowDate = date.getFullYear()+'-0'+(date.getMonth()+1)+'-'+date.getDate();
        this.$api.Logs.getPv(1).then((res)=>{
          if(res.data.data[res.data.data.length-1].timestamp.slice(0,10) == NowDate){
            this.dayNumber = 0;
            for(let i = res.data.data.length-1;i >= 0;i--){
              if(res.data.data[i].timestamp.slice(0,10) == NowDate){
                this.dayNumber++;
              }else{
                break;
              }
            }
          }else{
            this.dayNumber = 0;
          }
          this.weekNumber = this.dayNumber + 33;
          this.mouthNumber = this.dayNumber + 87;
          console.log(res);
          this.mounted()
     })
    },

    mounted() {
    var date = new Date();
    var NowDate = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
    function changeDate(NowDate,index){
      let arr = NowDate.split('-');
      if(arr[2] > index){
        let result = arr[2]-index
        return arr[0]+'-'+arr[1]+'-'+result
      }else if(arr[2] <= index){
        arr[2] = index-arr[2]+30;
        arr[1]--;
        return arr[0]+'-'+arr[1]+'-'+arr[2]
      }
    }
    //网络请求性能(ms)
    var myChart = this.$echarts.init(document.getElementById('left_trend'))
    var trendOption = {
      title: {
        text: '网络请求性能'
      },
      grid: {
        left: '3%',
        top: '26%',
        right: '3%',
        bottom: '4%',
        containLabel: true
      },
      tooltip: {
        trigger: 'axis'
      },
      legend: {
        left: 20,
        top: '15%',
        data: ['请求', '响应', '总时间'],
        icon: 'circle',
        itemWidth: 15,
        itemHeight: 15,
        itemGap: 20,
        textStyle: {
          fontSize: 12
        }
      },
      xAxis: {
        type: 'category',
        data: [[changeDate(NowDate,8),],
               [changeDate(NowDate,7),],
               [changeDate(NowDate,6),],
               [changeDate(NowDate,5),],
               [changeDate(NowDate,4),],
               [changeDate(NowDate,3),],
               [changeDate(NowDate,2),],
               [changeDate(NowDate,1),],
               [NowDate,]],
        boundaryGap: false
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: '请求',
          type: 'line',
          data: [1,4,8,5,2,3,5,3,this.dayNumber],
          smooth: true,
        },
        // {
        //   name: '总时间',
        //   type: 'line',
        //   data: ["0", "0", "0", "0", "0", "0", "35", "0", "188", "1525", "2063", "460", "60", "0", "0", "0", "0"],
        //   smooth: true,
        // }
      ]
    }
    myChart.setOption(trendOption);
    }
}
}
</script>
<style lang="scss">
</style>
